<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function getTwitStatus($twitter_user) {
	$jsonpath = "http://api.twitter.com/1/statuses/user_timeline/".$twitter_user.".json";
	$decode   = file_get_contents($jsonpath);
	$data 	  = json_decode($decode);
	return $data;
}

function fbAppsId() {
	return '344378649002791';
}

function getCategory() {
	$CI = get_instance();
    $CI->load->model('core_model');
	
	$cat 		= $CI->core_model->getalldata('tb_category', 'desc');
	$opentag 	= "<ul>";
	$closetag 	= "</ul>";
	$li			= "";
	foreach($cat as $c) {
		$li = $li."<li><a href=\"".base_url()."category/code/".$c['category_code']."\">".$c['category_name']."</a></li>";
	}
	return $opentag.$li.$closetag;
}

function penanggalan_indonesia(){
	$array_hari = array(1=>'Senin','Selasa','Rabu','Kamis','Jumat', 'Sabtu','Minggu');
	$array_bulan = array(1=>'Januari','Februari','Maret', 'April', 'Mei', 'Juni','Juli','Agustus','September','Oktober', 'November','Desember');

		$hari = $array_hari[date('N')];
		//Format Tanggal
		$tanggal = date ('j');
		//Array Bulan
		$bulan = $array_bulan[date('n')];
		//Format Tahun
		$tahun = date('Y');
	
	return $hari .', '.$tanggal." ".$bulan." ".$tahun;
}

function  tanggal_format_indonesia($tgl){
	$tanggal  =  substr($tgl,8,2);
	$bulan	=  getBulan(substr($tgl,5,2));
	$tahun	=  substr($tgl,0,4);
	return  $tanggal.' '.$bulan.' '.$tahun;
}

function tgl_mysql_to_php($tanggal){
	$array_hari = array(1=>'Senin','Selasa','Rabu','Kamis','Jumat', 'Sabtu','Minggu');
	$array_bulan = array(1=>'Januari','Februari','Maret', 'April', 'Mei', 'Juni','Juli','Agustus','September','Oktober', 'November','Desember');
	
	$hari_temp = date('l', strtotime($tanggal));
	$bulan_temp = date('F', strtotime($tanggal));
	
		$hari = $array_hari[$hari_temp];
		//Format Tanggal
		$tanggal = date ('d');
		//Array Bulan
		$bulan = $array_bulan[$bulan_temp];
		//Format Tahun
		$tahun = date('Y');
	
	return $hari .', '.$tanggal." ".$bulan." ".$tahun;
}

function  getBulan($bln){
	switch  ($bln){
	case  1:
	return  "Januari";
	break;
	case  2:
	return  "Februari";
	break;
	case  3:
	return  "Maret";
	break;
	case  4:
	return  "Maret";
	break;
	case  5:
	return  "Mei";
	break;
	case  6:
	return  "Juni";
	break;
	case  7:
	return  "Juli";
	break;
	case  8:
	return  "Agustus";
	break;
	case  9:
	return  "September";
	break;
	case  10:
	return  "Oktober";
	break;
	case  11:
	return  "November";
	break;
	case  12:
	return  "Desember";
	break;
	}
}

function cutstring($text, $length) {
	$isi_teks = htmlentities(strip_tags($text));
	$isi = substr($isi_teks,0,$length);
	$isi = substr($isi_teks,0,strrpos($isi," "));
	$isi = $isi.' ...';
	return $isi;
}

function dateformat($type, $date) {
	if($type == "time") {
		$format = "g:i A";
	} else {
		$format = "l, jS F Y";
	}
	$date = date_create($date);
	return date_format($date, $format);
}

function toAscii($strg) {
	$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $strg);
	$clean = strtolower(trim($clean, '-'));
	$clean = preg_replace("/[\/_|+ -]+/", '-', $clean);
	return $clean;
}
